package com.all.play.myapplication.adapter.inneradapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.all.play.myapplication.Bean.NewsResaultBeanData;
import com.all.play.myapplication.R;
import com.all.play.myapplication.utils.Constants;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/4/20.
 * Time: 2018/4/20  14:32
 */

public class MySeckillAdapter extends RecyclerView.Adapter<MySeckillAdapter.MySeckillinnerViewholder> {
    private Context mContext;
    private List<NewsResaultBeanData.ResultBean.SeckillInfoBean.ListBean> seckill_info;

    public MySeckillAdapter(Context mContext, List<NewsResaultBeanData.ResultBean.SeckillInfoBean.ListBean> seckill_info) {

        this.mContext = mContext;
        this.seckill_info = seckill_info;
    }

    @Override
    public MySeckillinnerViewholder onCreateViewHolder(ViewGroup parent, int viewType) {


        return new MySeckillinnerViewholder(View.inflate(mContext, R.layout.item_seckill,null));
    }

    @Override
    public void onBindViewHolder(MySeckillinnerViewholder holder, int position) {
        NewsResaultBeanData.ResultBean.SeckillInfoBean.ListBean listBean = seckill_info.get(position);
        Glide.with(mContext).load(Constants.BASE_URl_IMAGE+listBean.getFigure()).into(holder.iv_config);

        Log.i("nBindViewHolder", "onBindViewHolder: "+Constants.BASE_URl_IMAGE+listBean.getFigure());

        holder.tv_cover_prices.setText(listBean.getCover_price());
    }

    @Override
    public int getItemCount() {
        return seckill_info==null?0:seckill_info.size();
    }


    class MySeckillinnerViewholder extends RecyclerView.ViewHolder{

        ImageView iv_config;
        TextView  tv_cover_prices;
        public MySeckillinnerViewholder(View itemView) {
            super(itemView);
            iv_config= (ImageView) itemView.findViewById(R.id.iv_figure);
            tv_cover_prices= (TextView) itemView.findViewById(R.id.tv_cover_price);


            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (getLocationListener!=null){
                        getLocationListener.showlocate(getLayoutPosition());
                    }
                }
            });

        }
    }

    public interface GetLocationListener{
        void showlocate(int position);
    }

    private GetLocationListener getLocationListener;

    public void setGetLocationListener(GetLocationListener getLocationListener) {
        this.getLocationListener = getLocationListener;
    }
}
